//
//  SleepListCell.m
//  Ginix
//
//  Created by fzq on 2025/3/3.
//

#import "SleepListCell.h"

@interface SleepListCell()
@property (nonatomic,strong) UIView * bgView;
@property (nonatomic,strong) UIImageView * iconView;
@property (nonatomic,strong) UIImageView * arrow;
@property (nonatomic,strong) UILabel * nameLabel;
@property (nonatomic,strong) UILabel * infoLabel;
@property (nonatomic,strong) UILabel * timeLabel;
@end

@implementation SleepListCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];
    self.selectionStyle = UITableViewCellSelectionStyleNone;
}

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    
    if(self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]){
        [self setSubViewLayout];
    }
    return self;
}
-(void)setSubViewLayout{
    
    self.backgroundColor = UIColor.clearColor;
    self.contentView.backgroundColor = UIColor.clearColor;
    
    [self addSubview:self.bgView];
    [_bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(333 * FMScaleX, 120 * FMScaleX));
        make.center.equalTo(@0);
    }];
    [self.bgView addSubview:self.iconView];
    [_iconView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(120 * FMScaleX, 120 * FMScaleX));
        make.left.equalTo(@0);
        make.centerY.equalTo(@0);
    }];
    [self.bgView addSubview:self.arrow];
    [_arrow mas_makeConstraints:^(MASConstraintMaker *make) {
        make.size.mas_offset(CGSizeMake(30 * FMScaleX, 30 * FMScaleX));
        make.center.equalTo(self.iconView);
    }];
    [self.bgView addSubview:self.nameLabel];
    [_nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.iconView.mas_right).offset(24 * FMScaleX);
        make.top.equalTo(self.iconView.mas_top).offset(20 * FMScaleX);
    }];
    [self.bgView addSubview:self.infoLabel];
    [_infoLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.nameLabel);
        make.top.equalTo(self.nameLabel.mas_bottom).offset(5 * FMScaleX);
        make.right.mas_offset(- 20 * FMScaleX);
        make.height.mas_offset(40 * FMScaleX);
    }];
    [self.bgView addSubview:self.timeLabel];
    [_timeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.mas_offset(-20 * FMScaleX);
        make.bottom.mas_offset(-14 * FMScaleX);
    }];
}

-(void)setInfoModel:(SleepGroupListModel *)infoModel{
    
    [self.iconView sd_setImageWithURL:[NSURL URLWithString:infoModel.imageUrl]];
    self.nameLabel.text = infoModel.title;
    self.infoLabel.text = infoModel.describe;
    if(infoModel.duration > 60){
        self.timeLabel.text = [NSString stringWithFormat:@"%ldmin%lds",infoModel.duration / 60 , infoModel.duration % 60];

    }else{
        self.timeLabel.text = [NSString stringWithFormat:@"%lds",infoModel.duration];
    }
}

-(UIView *)bgView{
    
    if(!_bgView){
        _bgView = [[UIView alloc]init];
        _bgView.backgroundColor = RDRGBA(0xF8F9F6, 0.4);
        [_bgView setCornerRadius:10 * FMScaleX borderWidth:1 borderColor:RDRGBA(0xF8F9F6, 0.3)];
    }
    return _bgView;
}
-(UIImageView *)iconView{
    
    if(!_iconView){
        _iconView = [[UIImageView alloc]init];
        _iconView.contentMode = UIViewContentModeScaleAspectFit;
    }
    return _iconView;
}
-(UIImageView *)arrow{
    
    if (!_arrow) {
        _arrow = [[UIImageView alloc]init];
        _arrow.image = [UIImage imageNamed:@"Sleep_play_player"];
    }
    return _arrow;
}
-(UILabel *)nameLabel{
    
    if (!_nameLabel) {
        _nameLabel = [[UILabel alloc]init];
        _nameLabel.font = Semibold(15);
        _nameLabel.textColor = UIColor.whiteColor;
    }
    return _nameLabel;
}
-(UILabel *)infoLabel{
    
    if (!_infoLabel) {
        _infoLabel = [[UILabel alloc]init];
        _infoLabel.font = Regular(12);
        _infoLabel.textColor =UIColor.whiteColor;
        _infoLabel.numberOfLines = 0;
    }
    return _infoLabel;
}
-(UILabel *)timeLabel{
    
    if (!_timeLabel) {
        _timeLabel = [[UILabel alloc]init];
        _timeLabel.font = Regular(12);
        _timeLabel.textColor =UIColor.whiteColor;
    }
    return _timeLabel;
}
@end
